#include<iostream>

using namespace std;

#include<stdlib.h>
#include<string.h>

class Date
{
public:
	Date(int year = 0, int month = 0, int day = 0)
	{
		_year = year;
		_month = month;
		_day = day;
	}

	void Print()
	{
		cout << _year << "-" << _month << "-" << _day << endl;
	}


private:
	int _year;
	int _month;
	int _day;
};

typedef int DataType;

class Stack
{
public:
	Stack(DataType* a, int n)
	{
		_array = (int*)malloc(sizeof(int) * n);
		if (_array == NULL)
		{
			perror("malloc fail");
			return;
		}
		memcpy(_array, a, sizeof(int) * n);
		_top = n;
		_capacity = n;
	}

	Stack(int StackCapacity = 4)
	{
		_array = (int*)malloc(sizeof(int) * StackCapacity);
		if (_array == NULL)
		{
			perror("malloc fail");
			return;
		}
		_top = 0;
		_capacity = StackCapacity;
	}

	void Push(DataType x)
	{
		CheckCapacity();
		_array[_top++] = x;

	}

	Stack(const Stack& s)
	{
		_array = (int*)malloc(sizeof(s._array));
		if (_array == NULL)
		{
			perror("malloc fail");
			return;
		}

		memcpy(_array, s._array, sizeof(int) * (s._capacity));
		_top = s._top;
		_capacity = s._capacity;
	}


	~Stack()
	{
		if (_array)
		{
			free(_array);
			_array = nullptr;
			_top = 0;
			_capacity = 0;
		}
	}


private:
	void CheckCapacity()
	{
		if (_top == _capacity)
		{
			int newcapacity = _capacity * 2;
			DataType* temp = (DataType*)realloc(_array, newcapacity * sizeof(DataType));
			if (temp == NULL)
			{
				perror("realloc??!!!");
				return;
			}
			_array = temp;
			_capacity = newcapacity;
		}
	}
private:
	DataType* _array;
	int _top;
	int _capacity;
};


int main()
{
	//Date d1;
	//d1.Print();

	//Date d2(2025, 5, 16);
	//d2.Print();

	//Date d3(d2);
	//d3.Print();

	int a[10] = { 0 };

	Stack s1(a, 10);

	Stack s2;
	s2.Push(1);
	s2.Push(2);
	s2.Push(3);
	s2.Push(4);
	s2.Push(5);
	s2.Push(6);

	Stack s3(s2);

	return 0;
}